package gui;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.sql.SQLException;
import java.util.Vector;

import data.BankDatabase;

public class AdmView extends JPanel{
	
	private JButton btn_Back;
	private BankDatabase bdb;
	private Screen screen;	
	
	public AdmView(BankDatabase bdb, Screen screen) {
		
		this.bdb = bdb;
		this.screen = screen;
		
		setPreferredSize(new Dimension(550, 400));
		setLayout(new BorderLayout());

		JTable jt = new JTable();
		
		jt.setFont(new Font("SansSerif", Font.PLAIN, 14));
		jt.setDefaultRenderer(Object.class, new AlternateTableRowColorRenderer());
		
		JScrollPane scrollpane = new JScrollPane(jt);
		add(scrollpane);
		
		btn_Back = new JButton("Back");
		btn_Back.setFont(new Font("SansSerif", Font.PLAIN, 16));
		add(btn_Back, BorderLayout.PAGE_END);
	}
	
	public void addActionListener(ActionListener e){
		btn_Back.addActionListener(e);
	}
	
	public JButton getBack(){
		return btn_Back;
	}
		
//	// custom tablemodel extended by abstracttablemodel
//	private class MyTableModel extends AbstractTableModel{
//
//		public int getColumnCount() {
//	        return columnnames.size();
//	    }
//
//	    public int getRowCount() {
//	        return data.size();
//	    }
//
//	    public String getColumnName(int col) {
//	        return columnnames[col];
//	    }
//
//	    public Object getValueAt(int row, int col) {
//	        return data[row][col];
//	    }
//
//	    public Class getColumnClass(int c) {
//	        return getValueAt(0, c).getClass();
//	    }		
//	    
//		public void setValueAt(Object value, int row, int col) {
//	        data[row][col] = value;
//	        fireTableCellUpdated(row, col);
//	    }
//		
//		
//	}
	
	// Painting the jtable
	private class AlternateTableRowColorRenderer extends DefaultTableCellRenderer{

		Color currColor = Color.white;

		public AlternateTableRowColorRenderer() {
			setOpaque(true);
		}
		public Component getTableCellRendererComponent(JTable table, Object value, 
				boolean isSelected, boolean hasFocus, int row, int column) {
			if (row % 2 == 0) {
				currColor = Color.white;
			} 
			else {
				currColor = new Color(222, 222, 255);
			}
			if (isSelected) {
				super.setForeground(table.getSelectionForeground());
				super.setBackground(table.getSelectionBackground());
			} 
			else {
				super.setForeground(Color.black);
				super.setBackground(currColor);
			}
			setFont(table.getFont());
			setValue(value);
				
			return this;
		}
	} // end private class
	
} // end class AdmView
